package com.salesmanager.core.business.weichat.menu.weichat;

import com.salesmanager.core.utils.weichat.WeiChatHttpUtil;

/**
 * Created by Liutong on 2016/7/19.
 */
public class CreateWeichatMenu {

    public static void main() throws Exception {

        //获取到公众号的AccessToken
        String weiChatAccessToken = WeiChatHttpUtil.getWeiChatAccessToken();

        //向用户发送消息，此项目中没用到
        String jsonStr = "{"+"\"touser\":\""+"用户openid"+"\","
                +"\"msgtype\":\"text\","
                +"\"text\":{\"content\":\""+"文本内容content"+"\"}"+"}";
        String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN".replace("ACCESS_TOKEN",weiChatAccessToken);
        String result = WeiChatHttpUtil.sendPost(url, jsonStr.toString());
        System.out.println(result);

        //查询本公众号中菜单的信息
        String menuUrl = "https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=ACCESS_TOKEN".replace("ACCESS_TOKEN",weiChatAccessToken);
        String resultInfo = WeiChatHttpUtil.httpGet(menuUrl);
        System.out.println(resultInfo);


        //给公众号创建菜单（示例）
        String createMenu = " https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN".replace("ACCESS_TOKEN", weiChatAccessToken);
        String createJson = "{"+"\"button\":[{"+"\"type\":\"click\","+"\"name\":"+
                "\"bindWeichat\","+"\"key\":"+"\"绑定微信\""+"}]}";
        String createMenuResult = WeiChatHttpUtil.sendPost(createMenu, createJson.toString());
        System.out.println(createMenuResult);
    }
}
